package com.wngbms.netty._11tcp_perfect.server;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

public class ServerMsgDecoder extends ReplayingDecoder<Void> {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        int len = in.readInt();
        byte[] content = new byte[len];
        in.readBytes(content);

        ServerMsgEntity serverMsgEntity = new ServerMsgEntity();
        serverMsgEntity.setLen(len);
        serverMsgEntity.setContent(content);

        out.add(serverMsgEntity);
    }
}
